#include <iostream>
#include <string>
#include <map>
#include <ctime>

using namespace std;

class myCompare
{
public:
    int operator()(int v1, int v2)
    {
        return v1 > v2;
    }
};

void printMap(const map<int, string> &person)
{
    for (map<int, string>::const_iterator it = person.begin(); it != person.end(); ++it)
    {
        cout << "it->first: " << it->first << "  it->second: " << it->second << endl;
    }
    cout << endl;
}

void printMap(const map<int, string, myCompare> &person)
{
    for (map<int, string>::const_iterator it = person.begin(); it != person.end(); ++it)
    {
        cout << "it->first: " << it->first << "  it->second: " << it->second << endl;
    }
    cout << endl;
}

void test01()
{
    map<int, string> per1;
    per1.insert(pair<int, string>(1, "We"));
    per1.insert(make_pair<int, string>(7, "You"));
    per1.insert(make_pair(3, "I"));
    per1[4] = "They";
    printMap(per1);

    map<int, string> per2;
    per2.insert(pair<int, string>(34, "We"));
    per2.insert(make_pair<int, string>(345, "You"));
    per2.insert(make_pair(22, "I"));
    per2[48] = "They";
    printMap(per2);

    per1.swap(per2);
    printMap(per1);
    printMap(per2);

    cout << per1.size() << endl;
    cout << per1.empty() << endl;

    auto it1 = per1.find(345);
    int count = per1.count(345);
    if (it1 != per1.end())
    {
        cout << "found element! " << endl;
        cout << "count = " << count << endl;
        per1.erase(it1);
    }
    else
    {
        cout << "no element! " << endl;
    }

    printMap(per1);

    map<int, string> m1;
    m1.insert(make_pair(1, "one"));
    m1.insert(make_pair(5, "five"));
    m1.insert(make_pair(2, "two"));
    m1.insert(make_pair(3, "three"));
    printMap(m1);

    map<int, string, myCompare> m2;
    m2.insert(make_pair(1, "one"));
    m2.insert(make_pair(5, "five"));
    m2.insert(make_pair(2, "two"));
    m2.insert(make_pair(3, "three"));
    printMap(m2);
}
int main()
{
    srand((unsigned int)time(NULL));
    test01();
}



